<template>
	<div class="zy-content">
		<search :columns="searchData" @getSearch="getSearch(arguments)" key="search"></search>
		<div class="alarmConfiguration">
			<div class="list-layout mt16">
				<!-- 批量删除 批量导出  批量导入 下载模板 新增-->
				<div class="btns clear">
					<span class="title">生产订单</span>
					<Button @click="exportTemplateClick">导出</Button>
					<Button v-has="'Cuttingcase'" @click="closeCase(true)">结案</Button>
					<Button v-has="'CuttingCancelclosure'" @click="closeCase(false)">取消结案</Button>
					<Button v-has="'CuttingCancelclosure'" @click="closeCaseSap()">物料过账</Button>
				</div>
				<!-- 表格 -->
				<div class="tableContent">
					<Table
						class="resizable-table"
						border
						size="small"
						highlight-row
						@on-column-width-resize="
							(a, b, c, d) => {
								onColumnWidthResize(a, b, c, d, 'orderAdjustmentDeviceInfo');
							}
						"
						:columns="orderAdjustmentDeviceInfoList"
						ellipsis
						ref="selection"
						stripe
						:data="dataArr"
						@on-selection-change="onSelectChange"
						@on-row-click="rowClick"
					>
						<!-- <template #hourQuota="{ row, column }">
              <InputNumber ref="tableInput" :max="20" :min="0" :step="1" v-model="row.hourQuota"
                v-if="isEdit === column.slot + '-' + row._index" @on-blur="isEdit = ''" />
              <span v-else>{{ row.hourQuota }}</span>
            </template>-->
						<template slot-scope="{ row }" slot="action">
							<span class="operationBtn" @click.stop="viewNumble(row.orderCode, 1)">查看物料用量</span>
						</template>
					</Table>
				</div>
				<!-- 分页 -->
				<div class="pageWrap mt16">
					<pageLeftTitle :total="total" :selected="delIds.length" />
					<Page
						:total="total"
						:page-size="pageSize"
						:page-size-opts="pageSizeOption"
						:current="pageNum"
						@on-change="changePageNum"
						@on-page-size-change="changePageSize"
						show-sizer
						show-total
					/>
				</div>
			</div>
			<!-- echart -->
			<div class="list-layout echart_Box mt16">
				<div class="btns clear">
					<span class="title">排程视图</span>
					<span style="margin-left: 10px" v-for="(item, index) in stateColor" :key="index">
						<span style="font-size: 14px">{{ item.label }}</span>
						<span style="width: 10px; height: 10px; margin-left: 8px" :style="'background:' + item.value"></span>
					</span>
					<!-- <span style=>排程视图</span> -->
				</div>
				<div v-for="(item, index) in echartData" :key="index" class="one_line mt16">
					<Tooltip :content="item.deviceName">
						<div class="device_name">{{ item.deviceName }}:</div>
					</Tooltip>

					<div class="echart">
						<oneLineChart :index="'oneLine' + index" :mock="item.list" :deviceCode="item.deviceCode" />
					</div>
				</div>
				<div class="timeAxis">
					<span class="startTime">{{ startTime }}</span>
					<span class="endTime">{{ endTime }}</span>
				</div>
			</div>
			<search class="mt16" :columns="searchData2" @getSearch="getSearch2(arguments)" key="search1"></search>
			<!-- 已排程工单 -->
			<div class="list-layout mt16">
				<!-- 批量删除 批量导出  批量导入 下载模板 新增-->
				<div class="btns clear">
					<span class="title">开料工单</span>
					<Button v-has="'cuttingBatchImport'" @click="importExcelShow">
						{{ $t('common.Import') }}
					</Button>
					<Button v-has="'cuttingDownloadtemplate'" @click="exportTemplate">
						{{ $t('common.Download') }}
					</Button>
					<Button v-has="'cuttingDistribute'" @click="distribute(true)">下发</Button>
					<Button v-has="'cuttingRecallscheduling'" @click="distribute(false)">撤回排程</Button>
					<Button v-has="'Orderbinding'" @click="binding()">订单绑定</Button>
					<Button v-has="'cuttingdelete'" @click="delOrder">删除</Button>
				</div>
				<!-- 表格 -->
				<div class="tableContent">
					<Table
						class="resizable-table"
						border
						size="small"
						@on-column-width-resize="onColumnWidthResize"
						:columns="columnsK"
						ellipsis
						ref="selection"
						stripe
						:data="alData"
						@on-selection-change="onSelectChange1"
					>
						<template slot-scope="{ row }" slot="action">
							<span class="operationBtn" @click="viewNumble(row.orderCode, 1)">查看物料用量</span>
							<span class="operationBtn" @click="viewNumble(row.cuttingPlanCode, 2)">查看开料计划单</span>
						</template>
					</Table>
					<div class="pageWrap mt16">
						<pageLeftTitle :total="alTotal" :selected="delIds1.length" />
						<Page
							:total="alTotal"
							:page-size="alPageSize"
							:page-size-opts="pageSizeOption"
							:current="alPageNum"
							@on-page-size-change="alChangePageSize"
							@on-change="alChangePageNum"
							show-sizer
							show-total
						/>
					</div>
				</div>
			</div>
			<!-- 开料计划单 -->
			<Modal
				:mask-closable="false"
				v-model="viewNumbleDialog"
				:title="type == 2 ? '开料计划单' : '物料用量'"
				class="modal-content-layout"
				width="80%"
			>
				<div class="tableContent" v-show="type == 1">
					<Table
						class="resizable-table"
						border
						size="small"
						@on-column-width-resize="onColumnWidthResize"
						:columns="viewNumbleColumns1"
						ellipsis
						ref="selection"
						stripe
						:data="inventoryAnalysisData"
					></Table>
					<div class="pageWrap mt16">
						<pageLeftTitle :total="inventoryTotal" />
						<Page
							:total="inventoryTotal"
							:page-size="inventoryPageSize"
							:page-size-opts="pageSizeOption"
							:current="inventoryPageNum"
							@on-page-size-change="inventoryChangePageSize"
							@on-change="inventoryChangePageNum"
							show-sizer
							show-total
						/>
					</div>
				</div>
				<div class="tableContent" v-show="type == 2">
					<Row :gutter="20" class="mt16">
						<Table
							class="resizable-table"
							border
							size="small"
							:columns="columns1"
							@on-column-width-resize="onColumnWidthResize"
							ellipsis
							height="250"
							ref="selection"
							stripe
							:data="inventoryAnalysisData.plan1"
						>
							<template slot-scope="{ row }" slot="action">
								<span class="operationBtn" @click="print(row)">打印</span>
							</template>
						</Table>
						<div class="pageWrap mt16 info" style="margin-right: 40px">
							<span style="margin-right: 20px"> 卷料料宽：{{ inventoryAnalysisData.rollMaterialWidthSum }} </span>
							<span>卷重合计：{{ inventoryAnalysisData.weightSum }}</span>
						</div>
					</Row>
					<Row>
						<Table
							class="resizable-table mt16"
							border
							size="small"
							:columns="columns2"
							ellipsis
							ref="selection"
							height="230"
							stripe
							@on-column-width-resize="onColumnWidthResize"
							:data="inventoryAnalysisData.plan2"
						></Table>
						<div class="pageWrap mt16 info" style="margin-right: 40px">
							<span style="margin-right: 20px">料宽合计：{{ inventoryAnalysisData.materialWidthSum }}</span>
							<span>利用率：{{ inventoryAnalysisData.rate }}</span>
						</div>
					</Row>
				</div>
				<div slot="footer">
					<Button type="primary" :loading="loading" @click="viewNumbleDialog = false">{{ $t('maintenance.Confirmed') }}</Button>
				</div>
			</Modal>
			<Modal :mask-closable="false" v-model="distributeView" :title="distributeTitle ? '下发确认' : '撤回排程'" class="modal-title-layout">
				<div class="icon blue" v-if="distributeTitle == true">
					<i class="iconfont zy-common-wancheng"></i>
				</div>
				<div class="icon red" v-else>
					<i class="iconfont zy-common-shanchu"></i>
				</div>
				<p class="title">
					<span v-if="distributeTitle == true">是否确认工单下发生产</span>
					<span v-else>是否撤回工单下发生产</span>
				</p>
				<div slot="footer">
					<Button type="default" @click="distributeView = false">
						{{ $t('common.Cancle') }}
					</Button>
					<Button type="primary" :loading="loading" @click="distributeApi">
						{{ $t('maintenance.Confirmed') }}
					</Button>
				</div>
			</Modal>

			<commonModal ref="commonModal"></commonModal>
			<inputModal ref="inputModal"></inputModal>
		</div>
		<importExcelModal
			:importExcelStateF="importExcelState"
			v-if="importExcelState"
			url="/dms/materialCuttingPlan/importWork"
			@importExcelChange="importExcelChange"
		></importExcelModal>
	</div>
</template>

<script>
import { deleteApi } from '@/api/planManage/orderSchedul.js';
import search from '@/components/curd/searchList.vue';
import oneLineChart from './moduls/oneLineChart.vue';
import commonModal from '@/components/modalTypes/commonModal.vue';
import toggleTableOperation from '@/mixins/toggleTableOperation';
import importExcelModal from '@/components/importExcelNew.vue';
import inputModal from '@/components/modalTypes/inputModal.vue';
import fileDownload from 'js-file-download';

export default {
	name: 'productionPlan',
	components: {
		search,
		oneLineChart,
		commonModal,
		importExcelModal,
		inputModal,
	},
	mixins: [toggleTableOperation],
	data() {
		return {
			stateColor: [
				{
					label: '空闲',
					value: '#1db360', //绿色
				},
				{
					label: '已排程',
					value: '#f21d40', //绿色
				},
			],
			importExcelState: false,
			alTotal: 0,
			alPageSize: 10,
			alPageNum: 1,
			alData: [],
			alDel: [],
			viewNumbleDialog: false,
			viewNumbleColumns1: [
				{
					title: '序号',
					type: 'index',
					width: 80,
					align: 'center',
				},
				{
					title: '物料编号',
					key: 'materialCode',
					minWidth: 60,
					align: 'center',
					resizable: true,
					tooltip: true,
				},

				{
					title: '物料名称',
					key: 'materialName',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '物料类别',
					key: 'materialType',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				// {
				//   title: "所属仓库",
				//   key: "moldName",
				//   minWidth: 100,
				//   align: "center",
				//   resizable: true, tooltip: true,
				// },
				// {
				//   title: "现有库存存量",
				//   key: "moldModel",
				//   minWidth: 100,
				//   align: "center",
				//   resizable: true,
				//   tooltip: true,
				// },
				{
					title: '需求数量',
					key: 'needQuantity',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '计量单位',
					key: 'unit',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '材料牌号',
					key: 'materialMark',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '是否替代料',
					key: 'isReplaceMaterial',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
			],
			searchData: [
				{
					title: '作业工序',
					key: 'productionProcesses',
				},
				{
					title: '订单号',
					key: 'orderCode',
				},
				{
					title: '订单组号',
					key: 'workOrderGroup',
					type: 'search',
					dicUrl: '/dms/productionOrder/groupList',
					queryName: 'value',
					resultParams: 'res.data',
					params: {
						label: 'workOrderGroup',
						value: 'workOrderGroup',
					},
				},
				{
					title: '状态',
					key: 'state',
					type: 'select',
					dicData: [
						{ label: '完成', value: '完成' },
						{ label: '待排产', value: '待排产' },
						{ label: '已结案', value: '已结案' },
						{ label: '已排产', value: '已排产' },
						{ label: '取消结案', value: '取消结案' },
					],
				},
				{
					title: '产品编码',
					key: 'orderMaterialCode',
				},
				{
					title: '产品名称',
					key: 'materialName',
				},
				{
					title: '创建时间',
					key: 'time',
					type: 'daterange',
				},
				{
					title: '图号规格',
					key: 'customMaterialCode',
				},
				{
					title: 'MRP创建者',
					key: 'mrpController',
				},
				{
					title: '销售订单号',
					key: 'saleOrderCode',
				},
				{
					title: '备注1',
					key: 'remarks1',
				},
				{
					title: '备注2',
					key: 'remarks2',
				},
				{
					title: '是否物料过账',
					key: 'isPassBill',
					type: 'select',
					dicData: [
						{ label: '是', value: '是' },
						{ label: '否', value: '否' },
					],
				},
			],
			searchData2: [
				{
					title: '工单组号',
					key: 'groupItem',
				},
				{
					title: '工单号',
					key: 'workCode',
				},
			],
			columns: [
				{
					key: 'selection',
					type: 'selection',
					width: 60,
					align: 'center',
				},
				{
					title: '销售订单号',
					key: 'saleOrderCode',
					minWidth: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '订单号',
					key: 'orderCode',
					minWidth: 90,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '工序',
					key: 'productionProcesses',
					width: 90,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '订单组号',
					key: 'workOrderGroup',
					width: 200,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '客户',
					key: 'custom',
					width: 90,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '产品编号',
					key: 'orderMaterialCode',
					width: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '产品名称',
					key: 'materialName',
					width: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '产品型号',
					key: 'materialModel',
					width: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '图号规格',
					key: 'customMaterialCode',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '材料牌号',
					key: 'materialMark',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '计划数量',
					key: 'planQuantity',
					width: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '领料数',
					key: 'operationQuantity',
					width: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '提报数量',
					key: 'reportedQuantity',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '状态',
					key: 'state',
					width: 90,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '是否物料过账',
					key: 'isPassBill',
					width: 140,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '计划开始时间',
					key: 'planStartDate',
					width: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '计划完成日期',
					key: 'planFinishDate',
					width: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '计划交期',
					key: 'deliverDate',
					width: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '备注',
					key: 'remarks',
					width: 90,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: 'MES创建时间',
					key: 'createTime',
					width: 90,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '维护人',
					key: 'createBy',
					width: 90,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '备注1',
					key: 'remarks1',
					width: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '备注2',
					key: 'remarks2',
					width: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '备注3',
					key: 'remarks3',
					width: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '备注4',
					key: 'remarks4',
					width: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '备注5',
					key: 'remarks5',
					width: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '油品分类',
					key: 'oilClassification',
					width: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '客户牌号',
					key: 'customMark',
					width: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '超报比例',
					key: 'overreportingRatio',
					minWidth: 110,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '操作',
					slot: 'action',
					fixed: 'right',
					minWidth: 180,
					align: 'center',
				},
			],
			columnsK: [
				{
					key: 'selection',
					type: 'selection',
					width: 60,
					align: 'center',
				},
				{
					title: '工单号',
					key: 'workCode',
					minWidth: 90,
					align: 'center',
					resizable: true,
					tooltip: true,
				},

				{
					title: '产品编号',
					key: 'materialCode',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '工单组号',
					key: 'groupItem',
					minWidth: 150,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '设备编号',
					key: 'deviceCode',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '工装编号',
					key: 'moldCode',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '工装使用状态',
					key: 'moldState',
					minWidth: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '产品名称',
					key: 'materialName',
					width: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '产品型号',
					key: 'materialModel',
					width: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '图号规格',
					key: 'customMaterialCode',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '材料牌号',
					key: 'materialMark',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				// {
				//   title: "班次",
				//   key: "cla",
				//   minWidth: 100,
				//   align: "center",
				//   resizable: true, tooltip: true,
				// },
				{
					title: '计划数量',
					key: 'planProduceQuantity',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '生产数量',
					key: 'produceQuantity',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '状态',
					key: 'state',
					minWidth: 90,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '工单开始时间',
					key: 'workStartTime',
					minWidth: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '工单结束时间',
					key: 'workEndTime',
					minWidth: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '生产顺序',
					key: 'sort',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '客户',
					key: 'custom',
					minWidth: 90,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '操作',
					slot: 'action',
					fixed: 'right',
					minWidth: 280,
					align: 'center',
				},
			],
			columns1: [
				{
					title: '卷号',
					key: 'rollNumber',
					minWidth: 110,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '卷重(kg)',
					key: 'rollWeight',
					minWidth: 120,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '卷料料宽',
					key: 'rollMaterialWidth',
					minWidth: 110,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '操作',
					slot: 'action',
					// fixed: "right",
					width: 120,
					align: 'center',
				},
			],
			columns2: [
				{
					title: '条料用途',
					key: 'useTo',
					minWidth: 80,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '材料牌号',
					key: 'materialMark',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '条料料宽',
					key: 'materialWidth',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '条数',
					key: 'itemNum',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '客户名称',
					key: 'custom',
					minWidth: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '标识牌号',
					key: 'identifyMark',
					minWidth: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '备注',
					key: 'remarks',
					minWidth: 130,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
			],
			inventoryAnalysisData: [],
			inventoryPageNum: 1,
			inventoryPageSize: 10,
			inventoryTotal: 0,
			viewNumbleColumns: [
				{
					title: '序号',
					type: 'index',
					width: 80,
					align: 'center',
				},
				{
					title: '物料编号',
					key: 'materialCode',
					minWidth: 60,
					align: 'center',
					resizable: true,
					tooltip: true,
				},

				{
					title: '物料名称',
					key: 'materialName',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '物料类别',
					key: 'materialType',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				// {
				//   title: "所属仓库",
				//   key: "moldName",
				//   minWidth: 100,
				//   align: "center",
				//   resizable: true, tooltip: true,
				// },
				// {
				//   title: "现有库存存量",
				//   key: "moldModel",
				//   minWidth: 100,
				//   align: "center",
				//   resizable: true,
				//   tooltip: true,
				// },
				{
					title: '需求数量',
					key: 'needQuantity',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
				{
					title: '计量单位',
					key: 'unit',
					minWidth: 100,
					align: 'center',
					resizable: true,
					tooltip: true,
				},
			],
			selectRow: false,
			rows: {},
			orderCode: '',
			deviceList: [],
			isEdit: false,
			allCheck: false,
			loading: false,
			create: true,
			distributeView: false,
			searchParams: {},
			searchParams2: {},
			pageNum: 1,
			pageSize: 10,
			total: 0,
			dataArr: [],
			pageSizeOption: [10, 20, 40],
			delIds: [],
			delIds1: [],
			selection: [],
			distributeTitle: '',
			echartData: [],
			moldListRow: {},
			data: [],
			diaStatus: '',
			type: 1,
			inventoryMaterialCode: '',
		};
	},
	mounted() {
		this.getTableColumnsWidth(this.columns, 'orderAdjustmentDeviceInfo');
		this.searchList();
		this.getAlList();
	},
	methods: {
		print(row) {
			const that = this;
			console.log(this.$refs.inputModal.form.value);
			this.$refs.inputModal.showModal({
				title: '提示',
				type: 'number',
				desc: '请输入卷重(kg)',
				submit: (value) => {
					const form = (value.value - 0).toFixed(2);
					if (form <= 0) {
						that.$Message.error('请输入大于0的数');
						return;
					} else if (form > row.rollWeight) {
						that.$Message.error(`不能输入大于当前卷重(${row.rollWeight})的数`);
						return;
					}
					const data = {
						...row,
						rollWeight: form,
					};
					that.print1(data);
				},
			});
			this.$refs.inputModal.form.value = row.rollWeight + '';
		},
		print1(row) {
			const time = new Date().valueOf();
			let index = 0;
			const data = {
				deviceCode: row.deviceCode,
				list: [],
			};
			const arr = this.inventoryAnalysisData.plan2;
			for (let i = 0; i < arr.length; i++) {
				const itemNum = arr[i].itemNum;
				for (let j = 0; j < itemNum; j++) {
					let oneObj = {
						custom: '',
						materialLevel: 0,
						materialMark: '',
						materialWidth: '',
						orderCode: '',
						quantity: 0,
						rollNumber: '',
						tagSerialNumber: '',
					};
					oneObj.custom = arr[i].custom;
					oneObj.materialLevel = index + 1;
					oneObj.materialMark = arr[i].materialMark;
					oneObj.materialWidth = arr[i].materialWidth;
					oneObj.orderCode = arr[i].orderCode;
					oneObj.quantity = (row.rollWeight / row.rollMaterialWidth) * arr[i].materialWidth;
					oneObj.rollNumber = row.rollNumber;
					oneObj.tagSerialNumber = time + index;
					data.list.push(oneObj);
					index++;
				}
			}
			this.axios({
				url: '/dms/labelPrinting/printCuttingPlan',
				method: 'post',
				data: data,
			}).then((res) => {
				if (res.code == 200) {
					this.wifiPrint(res.data);
				}
			});
		},
		wifiPrint(data) {
			this.axios({
				url: '/dms/labelPrinting/print',
				method: 'post',
				data,
			}).then((res) => {
				if (res.code == 200) {
					this.$Message.success('打印成功');
					this.viewNumbleDialog = false;
				} else this.$Message.error('打印失败');
			});
		},
		exportTemplate() {
			const filName = '开料计划单导入模板';
			this.axios({
				url: '/dms/materialCuttingPlan/downloadTemplate',
				method: 'get',
				responseType: 'blob',
			}).then((res) => {
				fileDownload(res, filName + '.xls');
			});
		},
		closeCase(type) {
			if (this.delIds.length == 0) {
				this.$Message.warning({
					content: '至少选择一条数据',
					duration: 6,
					closable: true,
				});
				return;
			}
			const data = this.delIds.map((item) => {
				return {
					AUFNR: item.orderCode,
					WERKS: item.factory,
				};
			});
			this.axios({
				method: 'post',
				url: type ? '/dms/apiMethod/closeCase' : '/dms/apiMethod/cancelCloseCase',
				data: data,
			}).then((res) => {
				this.$Message.warning({
					content: res.msg,
					duration: 6,
					closable: true,
				});
			});
		},
		closeCaseSap() {
			if (this.delIds.length == 0) {
				this.$Message.warning({
					content: '至少选择一条数据',
					duration: 6,
					closable: true,
				});
				return;
			}
			const data = this.delIds.map((item) => {
				return {
					AUFNR: item.orderCode,
					WERKS: item.factory,
				};
			});
			console.log(data);
			this.axios({
				method: 'post',
				url: '/dms/apiMethod/closeCaseSap',
				data,
			}).then((res) => {
				this.$Message.warning({
					content: res.msg,
					duration: 6,
					closable: true,
				});
			});
		},
		delOrder() {
			const data = this.delIds1.map((item) => item.id);
			console.log(data);
			this.$refs.commonModal.showModal({
				type: 'delete',
				title: '删除提醒',
				desc: '确认是否删除',
				submit: () => {
					deleteApi(data).then((res) => {
						if (res.code === 200) {
							this.$Message.success(res.msg);
							this.refresh();
							// this.getAlList();
						} else {
							this.$Message.warning({
								content: res.msg,
								duration: 6,
								closable: true,
							});
						}
					});
				},
			});
		},
		getSearch(params) {
			this.searchParams = JSON.parse(JSON.stringify(params[0]));
			const time = this.searchParams.time;
			if (time && time.length == 2) {
				this.searchParams.startTime = this.searchParams.time[0];
				this.searchParams.endTime = this.searchParams.time[1];
				delete this.searchParams.time;
			}
			this.pageNum = 1;
			this.searchList();
			this.alData = [];
		},
		getSearch2(params) {
			this.searchParams2 = JSON.parse(JSON.stringify(params[0]));
			this.getAlList();
		},
		binding() {
			if (this.delIds.length < 1) {
				this.$Message.warning({
					content: '请选择一个生产订单',
					duration: 6,
					closable: true,
				});
				return;
			} else if (this.delIds1.length !== 1) {
				this.$Message.warning({
					content: '请选择一个开料工单',
					duration: 6,
					closable: true,
				});
				return;
			}
			let orderIds = this.delIds.map((item) => item.id);
			let workId = this.delIds1[0].id;
			this.axios({
				method: 'post',
				url: '/dms/materialCuttingPlan/associationOrder',
				data: {
					orderIds,
					workId,
				},
			}).then((res) => {
				if (res.code === 200) {
					this.refresh();
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				}
			});
		},
		viewNumble(code, type) {
			this.type = type;
			if (type == 2) {
				this.cuttingPlanCode = code;
				this.getInventoryList();
			} else {
				this.inventoryMaterialCode = code;
				this.getInventoryList2();
			}
		},
		getInventoryList2() {
			let params = {
				pageNum: this.inventoryPageNum,
				pageSize: this.inventoryPageSize,
				orderCode: this.inventoryMaterialCode,
			};
			this.axios({
				method: 'get',
				url: '/dms/productionWork/inventoryAnalysis',
				params,
			}).then((res) => {
				if (res.code === 200) {
					this.inventoryAnalysisData = res.data.records;
					this.inventoryTotal = res.data.total;
					this.viewNumbleDialog = true;
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				}
			});
		},
		getInventoryList() {
			let params = {
				// pageNum: this.inventoryPageNum,
				// pageSize: this.inventoryPageSize,
				cuttingPlanCode: this.cuttingPlanCode,
			};
			this.axios({
				method: 'get',
				url: '/dms/materialCuttingPlan/selectCuttingPlan',
				params,
			}).then((res) => {
				if (res.code === 200) {
					this.inventoryAnalysisData = res.data;
					this.viewNumbleDialog = true;
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				}
			});
		},
		getEchartData() {
			this.axios({
				method: 'get',
				url: '/dms/productionWork/produceView',
				params: {
					orderCode: this.orderCode,
				},
			}).then((res) => {
				if (res.code === 200) {
					this.echartData = res.data;
					if (res.data.length > 0) {
						this.startTime = this.$moment(res.data[0].list[0].startTime).format('YYYY-MM-DD HH:mm');
						this.endTime = this.$moment(res.data[0].list[res.data[0].list.length - 1].endTime).format('YYYY-MM-DD HH:mm');
					}
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				}
			});
		},
		distribute(status) {
			if (this.delIds1.length < 1) {
				this.$Message.warning({
					content: '只能选择一条数据',
					duration: 6,
					closable: true,
				});
				return;
			}
			this.distributeTitle = status;
			this.distributeView = true;
		},
		//导入
		importExcelShow() {
			this.importExcelState = true;
		},
		importExcelChange(val) {
			this.importExcelState = false;
			// if (val === "success") {
			// this.getInventoryList();
			// }
			this.getAlList();

		},
		changeNum(data) {
			this.pageNum = 1;
			this.searchParams = data;
			this.searchList();
		},
		changePageSize(pageSize) {
			this.pageSize = pageSize;
			this.searchList();
		},
		changePageNum(val) {
			this.pageNum = val;
			this.searchList();
		},
		alChangeNum(val) {
			this.alPageNum = 1;
			this.getAlList();
		},
		alChangePageSize(pageSize) {
			this.alPageSize = pageSize;
			this.getAlList();
		},
		alChangePageNum(val) {
			this.alPageNum = val;
			this.getAlList();
		},
		inventoryChangeNum(val) {
			this.inventoryPageNum = 1;
			this.getInventoryList2();
		},
		inventoryChangePageSize(pageSize) {
			this.inventoryPageSize = pageSize;
			this.getInventoryList2();
		},
		inventoryChangePageNum(val) {
			this.inventoryPageNum = val;
			this.getInventoryList2();
		},
		getAlList() {
			let params = {
				pageNum: this.alPageNum,
				pageSize: this.alPageSize,
				...this.searchParams2,
			};
			this.axios({
				method: 'post',
				url: '/dms/productionWork/cuttingPlanPage',
				data: params,
			}).then((res) => {
				if (res.code === 200) {
					this.alData = res.data.records;
					this.alTotal = res.data.total;
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				}
			});
		},
		distributeApi() {
			let myArray = [];
			this.delIds1.map((item, index) => {
				myArray.push(item.id);
			});
			this.axios({
				method: 'PUT',
				url: this.distributeTitle ? '/dms/productionWork/workdistribute' : '/dms/productionWork/revokeArrange',
				data: myArray,
			}).then((res) => {
				if (res.code === 200) {
					this.distributeView = false;
					this.$Message.success({
						content: res.msg,
						duration: 6,
						closable: true,
					});
					this.delIds1 = [];
					this.refresh();
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				}
			});
		},
		onSelectChange(selection) {
			let myArray = [];

			selection.map((item, index) => {
				myArray.push(item);
			});
			this.delIds = myArray;
		},
		onSelectChange1(selection) {
			// let myArray = [];
			// selection.map((item, index) => {
			//   myArray.push(item);
			// });
			this.delIds1 = JSON.parse(JSON.stringify(selection));
		},
		rowClick(row) {
			this.orderCode = row.orderCode;
			this.delIds1 = [];
			this.getEchartData();
			this.getAlList();
		},
		refresh() {
			this.getEchartData();
			this.searchList();
			this.getAlList();
			this.rows = [];
		},
		//导出
		exportTemplateClick() {
			let params = {};
			for (let key in this.searchParams) {
				if (this.searchParams[key]) {
					this.$set(params, key, this.searchParams[key]);
				}
			}
			const filName = this.$t('开料工单列表');
			this.axios({
				url: '/dms/productionOrder/cuttingPlanExport',
				method: 'post',
				data: params,
			}).then((res) => {
				if (res.code == 1) {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				} else {
					this.axios({
						url: '/dms/productionOrder/cuttingPlanExport',
						method: 'post',
						responseType: 'blob',
						data: params,
					}).then((res) => {
						fileDownload(res, filName + '.xlsx');
					});
				}
			});
		},
		//查询列表
		searchList() {
			let params = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
			};
			for (let key in this.searchParams) {
				if (this.searchParams[key]) {
					this.$set(params, key, this.searchParams[key]);
				}
			}
			this.axios({
				url: '/dms/productionOrder/cuttingPlanPage',
				method: 'post',
				data: params,
			}).then((res) => {
				if (res.code === 200) {
					this.dataArr = res.data.records.map((item) => ({
						...item,
						checked: false,
					}));
					this.total = res.data.total;
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				}
			});
		},
	},
};
</script>

<style scoped lang="scss">
.one_line {
	display: flex;
	flex-direction: row;

	.device_name {
		width: 90px;
		padding: 0 0 0 10px;
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
	}

	.echart {
		flex: 1;
		margin-left: 10px;
	}
}

.echart_Box {
	min-height: 200px;
}

.timeAxis {
	line-height: 25px;
}

.startTime {
	font-size: 12px;
	color: #333333;
	margin-left: 25px;
}

.endTime {
	font-size: 12px;
	color: #333333;
	float: right;
}
</style>
